//
//  TTCenterView.swift
//  TTWeibo
//
//  Created by 陶宏路 on 16/7/23.
//  Copyright © 2016年 陶路路. All rights reserved.
//

import UIKit
import SnapKit
class TTCenterView: UIView {
    
    var centerViewContrain:Constraint?
    
    var tthomeModel:TTHomeCellModel?{
        
        didSet{
            
//            textLable.text = tthomeModel?.cellModel?.text
            
            textLable.attributedText = tthomeModel?.attribute
        
            self.centerViewContrain?.uninstall()
            
            if tthomeModel?.cellModel?.pic_urls?.count <= 0{
                
                self.snp_makeConstraints { (make) -> Void in
                    
                    self.centerViewContrain = make.bottom.equalTo(textLable.snp_bottom).offset(10).constraint
                    
                    
                }
                pictureVie.hidden = true
                
            }else{
                
                pictureVie.tthomeModel = tthomeModel?.cellModel?.pic_urls

                self.snp_makeConstraints { (make) -> Void in
                    
                    self.centerViewContrain = make.bottom.equalTo(pictureVie.snp_bottom).offset(10).constraint
                
                }
                
                pictureVie.hidden = false

            }
        }
    }
    
    lazy var textLable:UILabel = {
       let lable = UILabel()
        lable.font = UIFont.systemFontOfSize(16)
        lable.textColor = UIColor.blackColor()
        lable.preferredMaxLayoutWidth = SCREENW - 20
        lable.numberOfLines = 0
        return lable
        
    }()
    
    lazy var pictureVie:TTPictureView = {
       let pic = TTPictureView()
        return pic
    }()
   
    override init(frame: CGRect) {
        
        super.init(frame: frame)
        
        setUpUI()
    }
    
    
    func setUpUI(){
        
        self.addSubview(textLable)
        self.addSubview(pictureVie)
        
        textLable.snp_makeConstraints { (make) -> Void in
            
            make.top.leading.equalTo(self).offset(10)
            
        }
        
        pictureVie.snp_makeConstraints { (make) -> Void in
            
            make.top.equalTo(textLable.snp_bottom).offset(10)
            make.leading.equalTo(self).offset((375-250)/2)
        
        }
        
        self.snp_makeConstraints { (make) -> Void in
            
          self.centerViewContrain = make.bottom.equalTo(pictureVie.snp_bottom).offset(10).constraint
        }
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
}
